#ifndef __i_text__
#define __i_text__

if(token.Matches(_("i_text"))&&(T.GetCount()==5))
{
    IsNotExtFunc = false;
    double X = calc(T[0]);
    double Y = calc(T[1]);
    double angle = calc(T[2])*DegToRad;   //ANGLE
    double S = calc(T[3]);   //SIZE
    wxString text = T[4];

    FT_Library library;
    FT_Face face;
    FT_Matrix matrix;

    bool error = FT_Init_FreeType( &library );
    if ( error )
    {
        CODE << _("Can't open library\n");
        break;
    }

    error = FT_New_Face( library, "/usr/share/fonts/truetype/freefont/FreeMono.ttf", 0, &face );
    if ( error == FT_Err_Unknown_File_Format )
    {

        CODE << _("can't open font\n");
        break;
    }
    else if ( error )
    {
        CODE << _("some error\n");
        break;
    }

    error = FT_Set_Char_Size( face, 16*64, 0 , S, S );


    if ( error )
    {
        printf("size error\n");
    }

    FT_GlyphSlot slot = face->glyph; /* a small shortcut */

    //FT_UInt glyph_index;
    FT_Vector pen;
    matrix.xx = (FT_Fixed)( cos(angle)*0x10000L);
    matrix.xy = (FT_Fixed)(-sin(angle)*0x10000L);
    matrix.yx = (FT_Fixed)( sin(angle)*0x10000L);
    matrix.yy = (FT_Fixed)( cos(angle)*0x10000L);

    pen.x = atof("0");
    pen.y = atof("0");

    //*******************************//
    for(uint n=0; n<text.Length(); n++)
    {
        FT_Set_Transform( face, &matrix, &pen );
        /* load glyph image into the slot (erase previous one) */
        error = FT_Load_Char( face,text.mb_str(wxConvUTF8)[n], FT_LOAD_RENDER );
        if ( error ) continue;


        /* ignore errors */ /* now, draw to our target surface */
        for(int c=0; c<slot->outline.n_contours; c++)
        {
            mPoint pd1,pd2;

            int start=0;
            if(c==0)
                start=0;
            else
                start=int(slot->outline.contours[c-1])+1;


            //******************************************//
            //**   CONTOUR DRAW                       **//
            //******************************************//
            for(int a=start; a<(slot->outline.contours[c]+1); a++)
            {
                mPoint p1,p2,cp;
                //******************************************************//
                //**         SUORA VIIVA
                //******************************************************//
                if(FT_CURVE_TAG(slot->outline.tags[a]) == FT_CURVE_TAG_ON)
                {
                    if(a>=slot->outline.contours[c])
                    {
                        pd1=mP(double(slot->outline.points[a].x)+X,double(slot->outline.points[a].y)+Y);
                        pd2=mP(double(slot->outline.points[start].x)+X,double(slot->outline.points[start].y)+Y);

                        I[iNum].add(eL(pd1,pd2));
                        pd1=pd2;

                      continue;
                    }

                    pd1=mP(double(slot->outline.points[a].x)+X,double(slot->outline.points[a].y)+Y);
                    if(FT_CURVE_TAG(slot->outline.tags[a+1]) == FT_CURVE_TAG_ON)
                    {
                        pd1=mP(double(slot->outline.points[a].x)+X,double(slot->outline.points[a].y)+Y);
                        pd2=mP(double(slot->outline.points[a+1].x)+X,double(slot->outline.points[a+1].y)+Y);

                        I[iNum].add(eL(pd1,pd2));
                        pd1=pd2;

                        //CONNEXTION
                        if((a+1)>=slot->outline.contours[c])
                        {
                            pd2=mP(double(slot->outline.points[start].x)+X,double(slot->outline.points[start].y)+Y);
                            I[iNum].add(eL(pd1,pd2));
                            pd1=pd2;
                        }
                    }
                    continue;
                }
                //************************************************************//
                //**
                //************************************************************//
                if( FT_CURVE_TAG( slot->outline.tags[a]) == FT_CURVE_TAG_CONIC )
                {
                    cp=mP(double(slot->outline.points[a].x)+X,double(slot->outline.points[a].y)+Y);

                    //***********************************************************//
                    //**
                    if(start==a)
                    {
                        pd1=mP(double(slot->outline.points[a].x)+X,double(slot->outline.points[a].y)+Y);
                        if( FT_CURVE_TAG( slot->outline.tags[slot->outline.contours[c]] ) == FT_CURVE_TAG_ON )
                        {
                            p1 = mP(double(slot->outline.points[slot->outline.contours[c]].x)+X,double(slot->outline.points[slot->outline.contours[c]].y)+Y);
                        }
                        if( FT_CURVE_TAG( slot->outline.tags[slot->outline.contours[c]] ) == FT_CURVE_TAG_CONIC )
                        {
                            p1 = mP(double(slot->outline.points[slot->outline.contours[c]].x)+X,double(slot->outline.points[slot->outline.contours[c]].y)+Y).GetMidPoint(
                                              mP(double(slot->outline.points[start].x)+X,double(slot->outline.points[start].y)+Y)

                                                                                                                                                                         );
                        }

                    }
                    else if( FT_CURVE_TAG( slot->outline.tags[a-1]) == FT_CURVE_TAG_CONIC )
                    {
                        p1 = mP(double(slot->outline.points[a-1].x)+X,double(slot->outline.points[a-1].y)+Y).GetMidPoint(cp);
                    }
                    else if( FT_CURVE_TAG( slot->outline.tags[a-1]) == FT_CURVE_TAG_ON )
                    {
                        p1 = mP(double(slot->outline.points[a-1].x)+X,double(slot->outline.points[a-1].y)+Y);
                    }

                    //***********************************************************//
                    //**
                    if( (slot->outline.contours[c]-1)<a)
                    {
                        if( FT_CURVE_TAG( slot->outline.tags[start]) == FT_CURVE_TAG_ON )
                        {

                            p2 = mP(double(slot->outline.points[start].x)+X,double(slot->outline.points[start].y)+Y);
                        }

                        else if( FT_CURVE_TAG( slot->outline.tags[slot->outline.contours[c]] ) == FT_CURVE_TAG_CONIC )
                        {
                            p2 = mP(double(slot->outline.points[slot->outline.contours[c]].x)+X,double(slot->outline.points[slot->outline.contours[c]].y)+Y).GetMidPoint(
                                              mP(double(slot->outline.points[start].x)+X,double(slot->outline.points[start].y)+Y)

                                                                                                                                                                         );
                        }


                    }
                    else if( FT_CURVE_TAG( slot->outline.tags[a+1]) == FT_CURVE_TAG_CONIC )
                    {
                        p2 = mP(double(slot->outline.points[a+1].x)+X,double(slot->outline.points[a+1].y)+Y).GetMidPoint(cp);
                    }
                    else if( FT_CURVE_TAG( slot->outline.tags[a+1]) == FT_CURVE_TAG_ON )
                    {
                        p2 = mP(double(slot->outline.points[a+1].x)+X,double(slot->outline.points[a+1].y)+Y);
                    }

                    //*********************//
                    double p=0;
                    pd1=p1;

                    mPointArray VA;
                    VA.Add(p1);
                    VA.Add(cp);
                    VA.Add(p2);
                    while(true)
                    {
                        p+=0.1;
                        if(p>1)p=1;
                        //pd2 = p1.Bezier(cp,p2,p);
                        pd2 = VA.Bezier(p);
                        I[iNum].add(eL(pd1,pd2));
                        pd1 = pd2;
                        if(AER(p,1))break;
                    }
                    VA.Clear();
                }


                continue;

                //printf("%d=",a);
                if( FT_CURVE_TAG( slot->outline.tags[a]) == FT_CURVE_TAG_ON)
                {
                    printf("-ON-");
                }
                if( FT_CURVE_TAG( slot->outline.tags[a]) == FT_CURVE_TAG_CONIC)
                {
                    printf("-CONIC-");
                }
                if( FT_CURVE_TAG( slot->outline.tags[a]) == FT_CURVE_TAG_CUBIC)
                {
                    printf("-CUBIC-");
                }
                //printf("\n");
            }
        }
        pen.x += slot->advance.x;
        pen.y += slot->advance.y;
    }
    continue;
}
#else
INFO << _("i_text(x,y,angle,size,text)<BR>");
if(token.Matches(_("i_text(*,*,*,*,*)")))
{
    INFO = _("<b>i_text</b>(x,y,angle,size,r,z,text)<BR>");
    INFO << _("(TEXT)<BR>");
    INFO << _("x<BR>");
    INFO << _("y<BR>");
    INFO << _("a = <BR>");
    INFO << _("s = <BR>");
    INFO << _("text =<BR>");
    INFO << _("<BR>");
    return true;
}
#endif
